package lt.mockos.app.client.cpu.event;

import com.google.web.bindery.event.shared.Event;
import com.google.web.bindery.event.shared.EventBus;
import com.google.web.bindery.event.shared.HandlerRegistration;

public class StepEvent extends Event<StepEvent.Handler> {

    public interface Handler {

        void onStep(StepEvent event);
    }

    private static final Type<StepEvent.Handler> TYPE = new Type<StepEvent.Handler>();

    public static HandlerRegistration register(EventBus eventBus, StepEvent.Handler handler) {
        return eventBus.addHandler(TYPE, handler);
    }

    private final String message;

    public StepEvent(String message) {
        this.message = message;
    }

    @Override
    public Type<StepEvent.Handler> getAssociatedType() {
        return TYPE;
    }

    public String getMessage() {
        return message;
    }

    @Override
    protected void dispatch(Handler handler) {
        handler.onStep(this);
    }
}
